/*
 * Created on 06-feb-2005
 *
 * TODO To change the template for this generated file go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
package com.juanfrivaldes.cio2005.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

/**
 * @author root
 *
 * TODO To change the template for this generated type comment go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
public class AccesoPrivadoAction extends BaseAction {

	private static Log log = LogFactory.getLog(AccesoPrivadoAction.class);
	
	protected ActionForward protectedExecute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		
		request.getSession(false).setAttribute("coautores", null);
		
		String destino=(String)request.getParameter("destino");
		log.trace("Destino deseado: "+destino);
		
		if(request.getParameter("forzar")!=null){
			request.getSession(true).removeAttribute("currentUser");
			log.trace("borramos el usuario actual");
		}
		
		// comprobamos que exista una sesion abierta y el usuario este autentificado
		if(request.getSession(false).getAttribute("currentUser")==null){
			
			request.setAttribute("destino",destino);
			return mapping.findForward("autentificar");
		}
			
		return mapping.findForward(destino);
		//return mapping.findForward("inicio");
	}
	
	
}
